<template>
  <div
    class="cus__state__container"
    :class="[state ? 'is__success' : 'is__error']"
    @click="$emit('onClick', state)"
  >
    <slot>
      <span>{{ state ? successText : errorText }}</span>
    </slot>
  </div>
</template>

<script lang="ts">
export default {
  name: 'cus-state',
  props: {
    state: {
      type: [Boolean, Number],
      default: () => false
    },
    successText: {
      type: String,
      default: '启用'
    },
    errorText: {
      type: String,
      default: '停用'
    }
  },
  emits: ['onClick']
}
</script>

<style lang="scss" scoped>
.cus__state__container {
  display: inline-block;
  padding: 0 15px 0 20px;
  height: 24px;
  line-height: 24px;
  border-radius: 3px;
  position: relative;
  cursor: pointer;
  transition: all .2s;
  &.is__success {
    color: #74c874;
    background: #f2f2f2;
    &::before {
      background: #74c874;
    }
  }
  &.is__error {
    color: #fc514f;
    background: #ffefeb;
    &::before {
      background: #fc514f;
    }
  }
  &:active {
    background: #eee;
    opacity: .8;
    transform: scale(.95);
  }
  &::before {
    content: '';
    display: block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 12px;
    margin-top: -2px;
  }
}
</style>